import VueRouter from 'vue-router'

//导入对应的路由文件
// import HomeContainer from './components/tabbar/HomeContainer.vue';
import MemberContainer from './components/tabbar/MemberContainer.vue';
import SearchContainer from './components/tabbar/SearchContainer.vue';
import ShopcarContainer from './components/tabbar/ShopcarContainer.vue';
// import NewsList from './components/news/NewsList.vue';
import newsInfo from './components/news/newsInfo.vue';
import PhotoList from './components/photos/photoList.vue';
import PhotoInfo from './components/photos/photoInfo.vue';
import GoodsList from './components/goods/goodsList.vue';
import GoodsInfo from './components/goods/goodsInfo.vue';
import GoodsDesc from './components/goods/goodsDesc.vue';
import GoodsComment from './components/goods/goodsComment.vue';
import Video from './components/tabbar/video.vue';
import Contact from './components/tabbar/contact.vue';
import Comment from './components/subcomponents/comment.vue';

var router = new VueRouter({
  //mode:'history',// 去掉路由地址的#
  routes: [
      {
          path:'/',// 默认进入路由[写在第一个]
          redirect:'/home'//重定向
      },
      {
          path:'/home',
          component:()=>import('./components/tabbar/HomeContainer.vue'),//动态加载（相当于异步）
          meta:{
              keepAlive:true,//this.$route.meta.keepAlive 缓存
              title:'首页'}
      },
      {
          path:'/member',
          component:MemberContainer,
          meta:{keepAlive:true,title:'会员'}
      },
      {
          path:'/shopcar',
          component:ShopcarContainer,
          meta:{keepAlive:true,title:'购物车'}
      },
      {
          path:'/search',
          component:SearchContainer,
          meta:{keepAlive:true,title:'搜索'}
      },
      {
          path:'/home/newsList',
          component:()=>import('./components/news/NewsList.vue'),
          meta:{title:'新闻列表'}
      },
      {
          path:'/home/newsInfo/:id',
          component:newsInfo,
          meta:{title:'新闻详情'}
      },
      {
          path:'/home/photoList',
          component:PhotoList,
          meta:{keepAlive:true,title:'课程列表'}
      },
      {
          path:'/home/PhotoInfo/:id',
          component:PhotoInfo,
          meta:{title:'课程详情'}
      },
      {
          path:'/home/GoodsList',
          component:GoodsList,
          meta:{keepAlive:true,title:'商品列表'}
      },
      {
          path:'/home/GoodsInfo/:id',
          component:GoodsInfo,
          name:"goodsInfo",
          meta:{title:'商品信息'}
      },
      {
          path:'/home/GoodsDesc/:id',
          component:GoodsDesc,
          name:"goodsDesc",
          meta:{title:'图文介绍'}
      },
      {
          path:'/home/GoodsComment/:id',
          component:GoodsComment,
          name:"goodsComment",
          meta:{title:'商品评论'}
      },
      {
          path:'/home/Video',
          component:Video,
          meta:{keepAlive:true,title:'视频专区'}
      },
      {
          path:'/home/Contact',
          component:Contact,
          meta:{keepAlive:true,title:'关于我们'}
      },
      {
          path:'/home/Comment',
          component:Comment,
          meta:{keepAlive:true,title:'留言反馈'}
      },
      {
          path:'*',// 错误路由[写在最后一个]
          redirect:'/home'//重定向
      }
  ],
    linkActiveClass:'mui-active' //覆盖默认路由高亮的类：link-router-active
});


// 实现title
//在进入路由之前 每一次都会执行此方法，全局钩子，有拦截功能
router.beforeEach(function (to,from,next) {
    document.title = to.meta.title;
    // if(to.path === '/list'){
    //   next({path:'/add'});//拦截
    // }else {
    //   next();
    // }
    next();
});
// 把路由对象暴露出去
export default router